package com.bwda.dsrs.filecenter.controller;

import com.bwda.dsrs.filecenter.domain.po.dspdbscanhistory.DspDbScanHistoryPo;
import com.bwda.dsrs.filecenter.domain.condition.dspdbscanhistory.DspDbScanHistoryCondition;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanhistory.DspDbScanHistoryQueryForm;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanhistory.DspDbScanHistoryUpdateForm;
import com.bwda.dsrs.filecenter.domain.form.dspdbscanhistory.DspDbScanHistoryCreateForm;
import com.bwda.dsrs.filecenter.domain.vo.dspdbscanhistory.DspDbScanHistoryVo;
import com.bwda.dsrs.filecenter.service.DspDbScanHistoryService;
import com.bwda.dsrs.filecenter.domain.exception.BusinessServiceException;
import com.bwda.dsrs.base.centerbase.response.CentreListResponse;
import com.bwda.dsrs.base.centerbase.response.CentreCutPageResponse;
import com.bwda.dsrs.base.centerbase.response.ResponseEntity;
import java.util.List;
import java.util.ArrayList;
import com.bwda.dsrs.base.util.CopyUtil;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * @author Administrator
 */
@RestController
@RequestMapping("/dspdbscanhistory")
@Api(value = "/dspdbscanhistory", tags = "敏感字段扫描结果历史表")
public class DspDbScanHistoryController extends BaseController {

	@Autowired
	private DspDbScanHistoryService dspDbScanHistoryService;

	@ApiOperation(value = "查询敏感字段扫描结果历史表",notes = "查询敏感字段扫描结果历史表",httpMethod = "GET")
	@RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<DspDbScanHistoryVo> query(@ApiParam(value = "id", required = true)@RequestParam Integer scanHistoryId) throws BusinessServiceException {
		DspDbScanHistoryPo po = dspDbScanHistoryService.queryWithValid(scanHistoryId);
		DspDbScanHistoryVo vo = CopyUtil.transfer(po, DspDbScanHistoryVo.class);
		return getSuccessResult(vo);
	}

	@ApiOperation(value = "查询敏感字段扫描结果历史表数量",notes = "查询敏感字段扫描结果历史表数量",httpMethod = "GET")
	@RequestMapping(value = "/queryCount", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<Integer> queryCount(@ModelAttribute@Valid DspDbScanHistoryQueryForm form) throws BusinessServiceException {
		DspDbScanHistoryCondition condition = this.getConditionByQueryForm(form);
		int count = dspDbScanHistoryService.queryCount(condition);
		return getSuccessResult(count);
	}

	@ApiOperation(value = "查询敏感字段扫描结果历史表列表",notes = "查询敏感字段扫描结果历史表列表",httpMethod = "GET")
	@RequestMapping(value = "/queryList", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<CentreListResponse<DspDbScanHistoryVo>> queryList(@ModelAttribute@Valid DspDbScanHistoryQueryForm form) throws BusinessServiceException {
		DspDbScanHistoryCondition condition = this.getConditionByQueryForm(form);
		List<DspDbScanHistoryPo> poList = dspDbScanHistoryService.queryList(condition);
		List<DspDbScanHistoryVo> voList = CopyUtil.transfer(poList, DspDbScanHistoryVo.class);
		return getSuccessResult(getListResponse(voList));
	}

	@ApiOperation(value = "查询敏感字段扫描结果历史表列表(带分页)",notes = "查询敏感字段扫描结果历史表列表(带分页)",httpMethod = "GET")
	@RequestMapping(value = "/queryPageList", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<CentreCutPageResponse<DspDbScanHistoryVo>> queryPageList(@ModelAttribute@Valid DspDbScanHistoryQueryForm form) throws BusinessServiceException {
		DspDbScanHistoryCondition condition = this.getConditionByQueryForm(form);
		List<DspDbScanHistoryVo> voList = new ArrayList<>();
		int count = dspDbScanHistoryService.queryCount(condition);
		if (count > 0) {
			List<DspDbScanHistoryPo> poList = dspDbScanHistoryService.queryList(condition);
			voList = CopyUtil.transfer(poList, DspDbScanHistoryVo.class);
		}
		return getSuccessResult(getPageResponse(form, count, voList));
	}

	@ApiOperation(value = "新增敏感字段扫描结果历史表",notes = "新增敏感字段扫描结果历史表",httpMethod = "POST")
	@RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity<DspDbScanHistoryVo> add(@ModelAttribute@Valid DspDbScanHistoryCreateForm form) throws BusinessServiceException {
		DspDbScanHistoryPo po = CopyUtil.transfer(form, DspDbScanHistoryPo.class);
		dspDbScanHistoryService.insert(po);
		DspDbScanHistoryVo vo = CopyUtil.transfer(po, DspDbScanHistoryVo.class);
		return getSuccessResult(vo);
	}

	@ApiOperation(value = "修改敏感字段扫描结果历史表",notes = "修改敏感字段扫描结果历史表",httpMethod = "POST")
	@RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity update(@ModelAttribute@Valid DspDbScanHistoryUpdateForm form) throws BusinessServiceException {
		DspDbScanHistoryPo po = CopyUtil.transfer(form, DspDbScanHistoryPo.class);
		dspDbScanHistoryService.update(po);
		return getSuccessResult();
	}

	@ApiOperation(value = "删除敏感字段扫描结果历史表",notes = "删除敏感字段扫描结果历史表",httpMethod = "POST")
	@RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST})
	public ResponseEntity delete(@ApiParam(value = "id", required = true)@RequestParam Integer scanHistoryId) throws BusinessServiceException {
		dspDbScanHistoryService.delete(scanHistoryId);
		return getSuccessResult();
	}

	/**
	 * DspDbScanHistoryQueryForm转换为DspDbScanHistoryCondition
	 *
	 * @param form
	 * @return
	 */
	private DspDbScanHistoryCondition getConditionByQueryForm(DspDbScanHistoryQueryForm form) {
		DspDbScanHistoryCondition condition = CopyUtil.transfer(form, DspDbScanHistoryCondition.class);
		return condition;
	}

}